﻿using System.Data.Objects;
using System.Configuration;
using System.Runtime.Remoting.Messaging;
using DomainData;

namespace GenericRepository
{
    public static class ContextFactory
    {
        public static ObjectContext GetContext()
        {
            var objectContext = CallContext.GetData(typeof(ContextFactory).FullName) as ObjectContext;

            if (objectContext == null)
            {
                return CreateContext();
            }

            return objectContext;
        }


        public static ObjectContext CreateContext()
        {
            var objectContext = new DomainEntitiesContainer();
            CallContext.SetData(typeof (ContextFactory).FullName, objectContext);
            return objectContext;
        }
    }
}

